package com.raven.play.stream.test.javadsl;

import akka.stream.alpakka.slick.javadsl.SlickSession;
import akka.stream.alpakka.slick.javadsl.SlickSession$;
import com.typesafe.config.ConfigFactory;
import scala.reflect.ClassTag;
import scala.reflect.ClassTag$;
import slick.basic.DatabaseConfig;
import slick.jdbc.JdbcProfile;
import slick.util.ClassLoaderUtil;

public class SlickHelper {

    public static SlickSession createSession(String path){
        ClassTag<JdbcProfile> classTag = ClassTag$.MODULE$.apply(JdbcProfile.class);
        DatabaseConfig databaseConfig = DatabaseConfig.forConfig(path, ConfigFactory.load(), ClassLoaderUtil.defaultClassLoader(), classTag);
        // SimpleDatabaseConfig<JdbcProfile> databaseConfig = new SimpleDatabaseConfig<>("slick-h2");
        // SlickSession session = SlickSession.forConfig(databaseConfig);
        // SlickSession session = SlickSession.forConfig("slick-h2");
        SlickSession session = SlickSession$.MODULE$.forConfig(databaseConfig);
        return session;
    }
}
